package com.peng.leetcode.search;

/**
 * FindMin1
 * 154. 寻找旋转排序数组中的最小值 II
 * https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array-ii/
 * <p>
 * Created on 2022/12/10
 *
 * @author lupeng
 */
public class FindMin2 {
    public int findMin(int[] nums) {
        int l = 0, r = nums.length - 1;
        while (l < r) {
            int mid = l + (r - l) / 2;
            if (nums[l] == nums[mid] && nums[mid] == nums[r]) {
                l++;
                r--;
            } else if (nums[mid] < nums[r]) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return nums[l];
    }
}
